package com.acme.bankapp.domain.bank;

import java.io.Serializable;

/**
 * Created by anton on 8/18/14.
 */
public class Client implements Serializable {
    // Fields
    private final String name;
    private final Gender gender;
    private AbstractAccount account;

    public Client(String name, Gender gender, AbstractAccount account) {
        this.name = name;
        this.gender = gender;
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public Gender getGender() {
        return gender;
    }

    public void getClientSalutation() {
        System.out.println(this.gender.getPrefix() + this.name);
    }

//    public Client(CheckingAccount account) {
//        this.account = account;
//    }

    public AbstractAccount getAccount() {
        return account;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Client)) {
            return false;
        }
        Client cl = (Client) obj;

        if (!cl.getName().equals(this.getName())) return false;
        if (!cl.getAccount().equals(this.getAccount())) return false;
        if (!cl.getGender().equals(this.getGender())) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + gender.hashCode();
        result = 31 * result + account.hashCode();
        return result;
    }

    @Override
    public String toString() {

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("\n===================================" + "\nInformation about the client:" + "\nName: ").append(this.getName()).append("\nGender: ").append(this.getGender()).append("\nAccounts:\n");
        stringBuffer.append(account.toString());
        return stringBuffer.toString();
    }
}
